﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterALSafa.Master" AutoEventWireup="true"
    CodeBehind="PayIncompleteVoucher.aspx.cs" Inherits="School.Pages.Accounting.PayIncompleteVoucher" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <script type="text/javascript">
        $(document).ready(
            $('.PayVoucher a').live('click', function () {
                var currentTime = new Date();
                var voucherDate = prompt("برجاء ادخال التاريخ", currentTime.getFullYear().toString() + "-" + (currentTime.getMonth() + 1).toString() + "-" + currentTime.getDate());

                var value = parseFloat($(this).parent().parent().find('.RemainingValue').text());
                var ivalue = parseFloat(prompt("برجاء ادخال القيمة المدفوعة", value));

                if (ivalue.toString() == "NaN")
                    alert("برجاء ادخال قيمة صحيحة");
                else if (ivalue > value)
                    alert("القيمة التى ادخلتها اكبر من القيمة المطلوبة و هى : " + value);
                else {
                    if (isDate(voucherDate)) {
                        window.open($(this).attr("href") + "&Paid=" + ivalue.toString() + "&date=" + voucherDate, 'الإيصال', "status=1,height=500,width:500");
                        $(this).parent().html("دفع");
                    }
                    else
                        alert('برجاء ادخال تاريخ صحيح');
                }

                return false;
            })
        );

        function y2k(number) { return (number < 1000) ? number + 1900 : number; }

        function isDate(date) {
            var dateArray = date.split('-');

            if (dateArray.length != 3)
                return false;

            var year = dateArray[0];
            var month = dateArray[1];
            var day = dateArray[2];
            var today = new Date();
            year = ((!year) ? y2k(today.getYear()) : year);
            month = ((!month) ? today.getMonth() : month - 1);
            if (!day) return false
            var test = new Date(year, month, day);
            if ((y2k(test.getYear()) == year) && (month == test.getMonth()) && (day == test.getDate()))
                return true;
            else
                return false
        }

    </script>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <table>
                <tr>
                    <td>
                        <table>
                            <tr>
                                <td>
                                    المبلغ الكلى
                                </td>
                                <td>
                                    <asp:Label ID="LblPaymentOrder" runat="server" Text="Label"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    المبلغ بعد التعديل
                                </td>
                                <td>
                                    <asp:Label ID="LblModefiedPaymentOrder" runat="server" Text="Label"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    المبلغ المدفوع
                                </td>
                                <td>
                                    <asp:Label ID="lblPaid" runat="server" Text="Label"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    المبلغ المتبقى
                                </td>
                                <td>
                                    <asp:Label ID="LblRemaining" runat="server" Text="Label"></asp:Label>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <asp:GridView ID="GridView1" runat="server" Width="100%" CssClass="Grid" HeaderStyle-CssClass="GridHeaderFooter"
                            FooterStyle-CssClass="GridHeaderFooter" PagerStyle-CssClass="GridPager" AlternatingRowStyle-CssClass="GridItemAltername"
                            AutoGenerateColumns="False">
                            <AlternatingRowStyle CssClass="GridItemAltername" />
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="ChkDiscount" runat="server" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="الخصم">
                                    <ItemTemplate>
                                        <asp:Label ID="Name" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                                        <asp:Label ID="LblDiscountId" Visible="false" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="النوع" Visible="false">
                                    <ItemTemplate>
                                        <asp:Label ID="Type" runat="server" Text='<%# GetType(Eval("Type")) %>'></asp:Label>
                                        <asp:Label Visible="false" ID="LblType" runat="server" Text='<%# Eval("Type") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="القيمة">
                                    <ItemTemplate>
                                        <asp:Label ID="Value" runat="server" Text='<%# GetValue(Eval("Type"),Eval("Value")) %>'></asp:Label>
                                        <asp:Label Visible="false" ID="LblValue" runat="server" Text='<%# Eval("Value") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <FooterStyle CssClass="GridHeaderFooter" />
                            <HeaderStyle CssClass="GridHeaderFooter" />
                            <PagerStyle CssClass="GridPager" />
                        </asp:GridView>
                        <asp:Button ID="Button1" runat="server" Text="حساب المبلغ" OnClick="Button1_Click" />
                        <asp:Button ID="Button2" runat="server" Text="حفظ" OnClick="Button2_Click" />
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:GridView ID="IncompleteVouchersGrid" runat="server" CssClass="Grid" HeaderStyle-CssClass="GridHeaderFooter"
                                FooterStyle-CssClass="GridHeaderFooter" PagerStyle-CssClass="GridPager" AlternatingRowStyle-CssClass="GridItemAltername"
                                AutoGenerateColumns="False">
                                <AlternatingRowStyle CssClass="GridItemAltername" />
                                <Columns>
                                    <asp:BoundField DataField="StudentNumber" HeaderText="رقم الطالب" />
                                    <asp:BoundField DataField="StudentName" HeaderText="اسم الطالب" />
                                    <asp:BoundField DataField="ExpenseName" HeaderText="نوع الإيراد" />
                                    <asp:BoundField DataField="OriginalValue" HeaderText="المبلغ" />
                                    <asp:BoundField DataField="PaidValue" HeaderText="المسدد" />
                                    <asp:BoundField ItemStyle-CssClass="RemainingValue" DataField="RemainingValue" HeaderText="المتبقى" />
                                    <asp:HyperLinkField ItemStyle-CssClass="PayVoucher" DataNavigateUrlFields="PaymentOrderNumber"
                                        DataNavigateUrlFormatString="PayLatePayment.aspx?PaymentOrder={0}&amp;Type=1"
                                        Text="دفع" />
                                </Columns>
                                <FooterStyle CssClass="GridHeaderFooter" />
                                <HeaderStyle CssClass="GridHeaderFooter" />
                                <PagerStyle CssClass="GridPager" />
                            </asp:GridView>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
